﻿

Public Class ZipperSetter

    'Load :
    Private Sub ZipSetter_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub
    'Associated Zip Designer :
    Private WithEvents _Designer As PanelZipDesigner
    Public Property Designer As PanelZipDesigner
        Get
            Return _Designer
        End Get
        Set(value As PanelZipDesigner)
            _Designer = value
        End Set
    End Property
    'Designer Events :
    Private Sub _Designer_NodeSelected(sender As Object, e As NodeSelectedEventArgs) Handles _Designer.NodeSelected
        If _SettingsEnabled = False Then
            SettingsEnabled = True
        End If
        KHG.ValuesPrimary.Image = _Designer.ZipTreeView.ImageList.Images.Item(e.SelectedNode.ImageKey)
        KHG.ValuesPrimary.Heading = e.SelectedNode.Text
        If TypeOf e.SelectedNode Is ZipNode Then
            If CType(e.SelectedNode, ZipNode).IsRootZipNode Then
                ZSP.TargetNode = CType(e.SelectedNode, ZipNode)
                BSHG_EntrySettings.Enabled = ButtonEnabled.False
                BSHG_ZipSettings.Enabled = ButtonEnabled.True
                BSHG_ZipSettings.PerformClick()
            Else
                ZSP.TargetNode = CType(e.SelectedNode, ZipNode)
                ESP.TargetNode = CType(e.SelectedNode, ISettable)
                ESP.KCB_Entry_Method.Enabled = False
                ESP.KCB_Entry_Level.Enabled = False
                BSHG_EntrySettings.Enabled = ButtonEnabled.True
                BSHG_ZipSettings.Enabled = ButtonEnabled.True
                BSHG_EntrySettings.PerformClick()
            End If
        Else
            ESP.TargetNode = CType(e.SelectedNode, ISettable)
            If TypeOf e.SelectedNode Is FileNode Then
                Dim hastofilter As Boolean = PF.IsFileNodeFiltered(CType(e.SelectedNode, FileNode))
                ESP.KCB_Entry_Method.Enabled = Not hastofilter
                ESP.KCB_Entry_Level.Enabled = Not hastofilter
            Else
                ESP.KCB_Entry_Method.Enabled = True
                ESP.KCB_Entry_Level.Enabled = True
            End If
            BSHG_EntrySettings.Enabled = ButtonEnabled.True
            BSHG_ZipSettings.Enabled = ButtonEnabled.False
            BSHG_EntrySettings.PerformClick()
        End If
    End Sub
    Private Sub _Designer_RootZipNodeDeleted(sender As Object, e As System.EventArgs) Handles _Designer.RootZipNodeDeleted
        Me.SettingsEnabled = False
        KHG.ValuesPrimary.Image = Nothing
        KHG.ValuesPrimary.Heading = ""
    End Sub
    Private Sub _Designer_RootZipNodeCreated(sender As Object, e As RootZipNodeCreatedEventArgs) Handles _Designer.RootZipNodeCreated
        SettingsEnabled = True
    End Sub
    'Select a Settings Panel :
    Private Sub SelectSettingsPanel(ByVal pan As String)
        Me.SuspendLayout()
        Dim pane As Control
        Dim bshg As ButtonSpecHeaderGroup
        ESP.Visible = False
        BSHG_EntrySettings.Checked = ButtonCheckState.Unchecked
        ZSP.Visible = False
        BSHG_ZipSettings.Checked = ButtonCheckState.Unchecked
        PF.Visible = False
        BSHG_Filters.Checked = ButtonCheckState.Unchecked
        Select Case pan
            Case "EntrySettings"
                pane = ESP
                bshg = BSHG_EntrySettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
            Case "ZipSettings"
                pane = ZSP
                bshg = BSHG_ZipSettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
            Case "Filters"
                pane = PF
                bshg = BSHG_Filters
                BSHG_ApplySettings.Enabled = ButtonEnabled.False
                BSHG_CancelSettings.Enabled = ButtonEnabled.False
                BSHG_ResetSettings.Enabled = ButtonEnabled.False
            Case Else
                pane = ESP
                bshg = BSHG_EntrySettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
        End Select
        bshg.Checked = ButtonCheckState.Checked
        pane.Visible = True
        pane.BringToFront()
        Me.ResumeLayout()
    End Sub
    'Showing / Hiding ZipSetter :
    Private _SettingsVisible As Boolean = True
    Public Property SettingsVisible As Boolean
        Get
            Return _SettingsVisible
        End Get
        Set(value As Boolean)
            If _SettingsVisible <> value Then
                Me.SuspendLayout()
                _SettingsVisible = value
                If _SettingsVisible = True Then
                    Me.AutoSize = False
                    BSHG_Toogle.Image = My.Resources.Img_Up
                    BSHG_Toogle.ToolTipTitle = "Hide Settings"
                Else
                    Me.AutoSize = True
                    BSHG_Toogle.Image = My.Resources.Img_Down
                    BSHG_Toogle.ToolTipTitle = "Show Settings"
                End If
                Me.ResumeLayout()
            End If
        End Set
    End Property
    Private _SettingsEnabled As Boolean = True
    Public Property SettingsEnabled As Boolean
        Get
            Return _SettingsEnabled
        End Get
        Set(value As Boolean)
            If _SettingsEnabled <> value Then
                Me.SuspendLayout()
                _SettingsEnabled = value
                If _SettingsEnabled = True Then
                    _SettingsEnabled = True
                    BSHG_Toogle.Enabled = ButtonEnabled.True
                Else
                    _SettingsEnabled = False
                    If _SettingsVisible = True Then
                        BSHG_Toogle.PerformClick()
                    End If
                    BSHG_Toogle.Enabled = ButtonEnabled.False
                End If
                Me.ResumeLayout()
            End If
        End Set
    End Property

    'Selection Panel :
    Private Sub BSHG_EntrySettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_EntrySettings.Click
        SelectSettingsPanel("EntrySettings")
    End Sub
    Private Sub BSHG_ZipSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ZipSettings.Click
        SelectSettingsPanel("ZipSettings")
    End Sub
    Private Sub BSHG_Filters_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Filters.Click
        SelectSettingsPanel("Filters")
    End Sub
    'Toogle Visible / Hidden State :
    Private Sub BSHG_Toogle_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Toogle.Click
        Me.SettingsVisible = Not Me.SettingsVisible
    End Sub
    'Actions :
    Private Sub BSHG_ResetSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ResetSettings.Click
        If ESP.Visible = True Then
            ESP.Reset()
        ElseIf ZSP.Visible = True Then
            ZSP.Reset()
        End If
    End Sub
    Private Sub BSHG_CancelSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_CancelSettings.Click
        If ESP.Visible = True Then
            ESP.Cancel()
        ElseIf ZSP.Visible = True Then
            ZSP.Cancel()
        End If
    End Sub
    Private Sub BSHG_ApplySettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ApplySettings.Click
        If ESP.Visible = True Then
            ESP.Apply()
        ElseIf ZSP.Visible = True Then
            ZSP.Apply()
        End If
    End Sub

End Class
